<template>
  <el-dialog
    :title="pageType===0?'新增点数配置':'点数配置修改'"
    :visible.sync="dialogVisible"
    width="70%"
    destroy-on-close
    append-to-body
    custom-class="k-dilaog"
    @closed="closedEvent">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="人民币">
        <el-input style="width: 180px" v-model="form.money"></el-input>
      </el-form-item>
      <el-form-item label="卡密点数">
        <el-input style="width: 180px" v-model="form.point"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
     <el-button @click="dialogVisible = false">取 消</el-button>
     <el-button type="primary" @click="clickSureBtn" :loading="loading">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import request from '@/utils/request';

export default {
  name:"pointAmountDialog",
  data(){
    return{
      dialogVisible:false,
      loading:false,
      form:{},
      callBack:null,
      pageType:0,//0新增1编辑
      id:null
    }
  },
  methods:{
    openDiaolog(pageType,id,block){
      this.pageType = pageType;
      this.id = id;
      this.callBack = block;
      this.dialogVisible = true;
      if (this.pageType === 1){
        this.requestDataDetail();
      }
    },
    clickSureBtn(){
      if (!this.form.money){
        this.$message.error("请输入人民币");
        return
      }
      if (!this.form.point){
        this.$message.error("请输入卡密点数");
        return
      }
      if (this.pageType === 0){
        this.requestDataAdd();
      }else {
        this.requestDataEdit();
      }
    },
    closedEvent(){
      this.form = {};
    },
    //网络-查询
    requestDataDetail(){
      request({
        url:`/point_config/${this.id}`,
        method:'get',
        data: this.form,
      }).then(response =>{
        this.form = response.data;
      })
    },
    //网络-根据ID修改用户信息
    requestDataEdit(){
      this.loading = true;
      request({
        url:`/point_config`,
        method:'put',
        data: this.form,
      }).then(response =>{
        this.loading = false;
        this.callBack();
        this.$message.success(response.msg);
        this.dialogVisible = false;
      })
    },
    //网络-新增
    requestDataAdd(){
      this.loading = true;
      request({
        url:`/point_config`,
        method:'post',
        data: this.form,
      }).then(response =>{
        this.loading = false;
        this.callBack();
        this.$message.success(response.msg);
        this.dialogVisible = false;
      })
    }
  }
}

</script>
